#include "EbnActionManager.h"

CEbnActionManager::CEbnActionManager()
{
}

CEbnActionManager::~CEbnActionManager()
{
    clear();
}

void CEbnActionManager::clear()
{
    vector<CEbnAction *>::iterator itAction;
    CEbnAction * pAction = NULL;

    for (itAction = mActions.begin(); itAction != mActions.end(); itAction++)
    {
        pAction = (* itAction);

        delete pAction;
        pAction = NULL;
    }

    mActions.clear();
}

CEbnAction * CEbnActionManager::addAction(string actionName)
{
    CEbnAction * pAction = getAction(actionName);

    if (NULL == pAction)
    {
        pAction = new CEbnAction(actionName);
        mActions.push_back(pAction);
    }

    return pAction;
}

void CEbnActionManager::removeAction(CEbnAction * action)
{
    vector<CEbnAction *>::iterator itAction;
    CEbnAction * pAction = NULL;

    for (vector<CEbnAction *>::iterator it = mActions.begin(); it != mActions.end(); it++)
    {
        if (action == (* it))
        {
            itAction = it;
        }
    }

    pAction = (*itAction);

    if (pAction)
    {
        delete pAction;
        pAction = NULL;

        mActions.erase(itAction);
    }
}

void CEbnActionManager::removeAction(string actionName)
{
    CEbnAction * pAction = NULL;

    pAction = getAction(actionName);

    removeAction(pAction);

}

CEbnAction * CEbnActionManager::getAction(string actionName)
{
    vector<CEbnAction *>::iterator itAction;
    for (itAction = mActions.begin(); itAction != mActions.end(); itAction++)
    {
        if (0 == (*itAction)->getName().compare(actionName))
        {
            return (*itAction);
        }
    }

    return NULL;
}

bool CEbnActionManager::hasAction(string actionName)
{
    if(NULL == getAction(actionName))
    {
        return false;
    }

    return true;
}
